package com.mingqijia.gassafety.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mingqijia.gassafety.db.entity.Department;
import com.mingqijia.gassafety.db.entity.auth.CompanyEntry;
import com.mingqijia.gassafety.db.mapper.DepartmentMapper;
import com.mingqijia.gassafety.db.mapper.auth.CompanyMapper;
import com.mingqijia.gassafety.job.service.DepartmentService;
import com.mingqijia.gassafety.shared.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wanghai
 * @since 2022-03-15
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {

    @Autowired
    CompanyMapper companyMapper;
    @Autowired
    DepartmentMapper departmentMapper;

    public String getPath(String spId) {
        //Company表rel_id字段关联 Department 表id字段
        QueryWrapper<CompanyEntry> entryQueryWrapper = new QueryWrapper<>();
        entryQueryWrapper.lambda().eq(CompanyEntry::getId,spId)
                .eq(CompanyEntry::getIsDeleted, Constants.IS_DELETED_FALSE);
        CompanyEntry companyEntry = companyMapper.selectOne(entryQueryWrapper);

        QueryWrapper<Department> departmentQueryWrapper = new QueryWrapper<>();
        departmentQueryWrapper.lambda().eq(Department::getId, companyEntry.getRelId());
        Department department = departmentMapper.selectOne(departmentQueryWrapper);
        if (department != null) {
            return department.getPath();
        } else {
            return "";
        }
    }
}
